package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class NursingProjectServiceImpl implements com.zzyl.service.NursingProjectService {
    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    /**
     * 护理项目的分页查询
     *
     * @param name
     * @param pageNum
     * @param pagSize
     * @param status
     * @return
     */
    @Override
    public PageResponse<NursingProjectVo> selectByPage(String name, Integer pageNum, Integer pagSize, Integer status) {
        //1、实行分页
        PageHelper.startPage(pageNum,pagSize);
        //2、调用mapper方法查询分页
        Page<NursingProjectVo> page = nursingProjectMapper.selectByPage(name, status);
        //返回结果
        return PageResponse.of(page,NursingProjectVo.class);
    }

    /**
     * 新增
     *
     * @param nursingProjectDto
     */
    @Override
    public void add(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        nursingProject.setCreateTime(new Date());
        nursingProject.setUpdateTime(new Date());
        nursingProjectMapper.insert(nursingProject);
    }

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Override
    public NursingProjectVo getById(Long id) {
        return nursingProjectMapper.selectById(id);
    }

    /**
     * 更新
     *
     * @param nursingProjectDto
     */
    @Override
    public void update(NursingProjectDto nursingProjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingProjectDto, NursingProject.class);
        nursingProjectMapper.update(nursingProject);
    }

    /**
     * 删除护理项目
     *
     * @param id
     */
    @Override
    public void delete(Long id) {
        nursingProjectMapper.delete(id);
    }

    /**
     * 修改启用、禁用
     *
     * @param id
     * @param status
     */
    @Override
    public void setStatus(Long id, Integer status) {
        nursingProjectMapper.updateStatus(id,status);
    }
}
